package com.example.apple.myrecyclewiew;

import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.widget.Toast;

import java.util.ArrayList;
import java.util.List;

public class MainActivity extends AppCompatActivity {
    private RecyclerView recyclerView;
    private RecyclerView.LayoutManager layoutManager;
    private MyAdapter myAdapter;

    List<ArticleBean> list;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        recyclerView=(RecyclerView)findViewById(R.id.recyclerview);

        layoutManager=new LinearLayoutManager(this);
        recyclerView.setLayoutManager(layoutManager);
        list =getData();
        myAdapter=new MyAdapter(this);
        myAdapter.setList(list);
        recyclerView.setAdapter(myAdapter);
    }
    private List<ArticleBean> getData(){
        List<ArticleBean> list=new ArrayList<ArticleBean>();
        ArticleBean articleBean;

        articleBean=new ArticleBean();
        articleBean.setArticleId(1);
        articleBean.setTitle("title 1");
        articleBean.setImgid(R.drawable.f1);
        articleBean.setTime("2017-5-1");
        articleBean.setDescription("11");
        list.add(articleBean);

        articleBean=new ArticleBean();
        articleBean.setArticleId(1);
        articleBean.setTitle("title 1");
        articleBean.setImgid(R.drawable.f1);
        articleBean.setTime("2017-5-1");
        articleBean.setDescription("11");
        list.add(articleBean);
        articleBean=new ArticleBean();
        articleBean.setArticleId(1);
        articleBean.setTitle("title 1");
        articleBean.setImgid(R.drawable.f1);
        articleBean.setTime("2017-5-1");
        articleBean.setDescription("11");
        list.add(articleBean);

        articleBean=new ArticleBean();
        articleBean.setArticleId(1);
        articleBean.setTitle("title 1");
        articleBean.setImgid(R.drawable.f1);
        articleBean.setTime("2017-5-1");
        articleBean.setDescription("11");
        list.add(articleBean);
        articleBean=new ArticleBean();
        articleBean.setArticleId(1);
        articleBean.setTitle("title 1");
        articleBean.setImgid(R.drawable.f1);
        articleBean.setTime("2017-5-1");
        articleBean.setDescription("11");
        list.add(articleBean);

        articleBean=new ArticleBean();
        articleBean.setArticleId(1);
        articleBean.setTitle("title 1");
        articleBean.setImgid(R.drawable.f1);
        articleBean.setTime("2017-5-1");
        articleBean.setDescription("11");
        list.add(articleBean);

        return list;
    }
    public class MainActivity extends AppCompatActivity {
        private RecyclerView recyclerView;
        private RecyclerView.LayoutManager layoutManager;
        private MyAdapter myAdapter;
        List<ArticleBean> list ;
        ArticleListener articleListener = new ArticleListener() {
            @Override
            public void onResponse(List<ArticleBean> listbean) {
                list = listbean;
                myAdapter.setList(list);
            }

            @Override
            public void onFail(String msg) {
                Toast.makeText(MainActivity.this,"fall:"+msg,Toast.LENGTH_SHORT).show();

            }

        };




        @Override
        protected void onCreate(Bundle savedInstanceState) {
            super.onCreate(savedInstanceState);
            setContentView(R.layout.activity_main);
            init();
            ArticleModel articleModel =new ArticleModel();
            articleModel.getResultList("article",2,"8soafn3tpaj0efuab5jvmpbhr4",articleListener);
        private void init(){


            recyclerView=(RecyclerView)findViewById(R.id.recyclerview);

            layoutManager=new LinearLayoutManager(this);
            recyclerView.setLayoutManager(layoutManager);
            myAdapter=new MyAdapter(this);
            myAdapter.setList(list);
            recyclerView.setAdapter(myAdapter);
            ArticleModel articleModel =new ArticleModel();
            articleModel.getResultList("article",2,"8soafn3tpaj0efuab5jvmpbhr4",articleListener);

        }
